<?php

 /**
  * Objektklasse "Database" 
  * Hier steht alle objektbezogene Logik! 
  * @author Projektgruppe mCRM
  * @version 4.0.1
  */
  
  require_once("model/database.inc.php");
  
 // 
 class contact
 {
	var $id;
 
 /**
  * Verbindung zur Datenbank
  */
  
    function __construct($contact_id)
	{
		if(isset($contact_id))
		 		$this->id = $contact_id;
		
	}
  
	function getdata()
	{
			$db = new database();
			$sqlstring="Select * from contact WHERE contactid  = '". $this->id ."'";
			$information = $db->sendsql($sqlstring);
			return $information;
	}
	
	function gethistory()
	{
			$db = new database();
			$sqlstring="Select no, contactid, Name, Notiz, Datum from notizen WHERE contactid like '%". $id ."%' ORDER BY Datum DESC";			
			$information = $db->sendsql2($sqlstring);
			return $information;
	}
	

	 
	function updatecontact($firstname,$lastname,$address1_line1,$address1_city,$telephone1,$emailaddress1,$address1_postalcode)
					{ 
					 $sql= "UPDATE contact 
								SET ";
							 if($firstname!="") 		$sql  .= "firstname		='". $firstname	."',";
							 if($lastname!="") 			$sql  .= "lastname		='". $lastname	."',";
							 if($address1_line1!="") 	$sql  .= "address1_line1		='". $address1_line1	."',";
							 if($address1_city!="") 	$sql  .= "address1_city		='". $address1_city	."',";
							 if($telephone1!="") 		$sql  .= "telephone1		='". $telephone1	."',";
							 if($emailaddress1!="") 	$sql  .= "emailaddress1		='". $emailaddress1	."',";
							 if($address1_postalcode!="") $sql  .= "address1_postalcode		='". $address1_postalcode	."',";
							 $sql=substr($sql, 0, -1);						
							 $sql .=" WHERE contactid='". $this->id ."';";
					
					$db = new database();
					$db->savesql($sql);
					
					}
					
	function createcontact($firstname,$lastname)
					{ 
					 $sql= "insert into contact (firstname, lastname) 
								values('". $firstname ."','". $lastname ."');";							
					
					$db = new database();
					$this->id = $db->savesql($sql);
					return $this->id;
					}
	 
}
?>